<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <style>
      /* html {
        font-size: 20px;
      } */

      .box-px {
        width: 300px;
        height: 100px;
        background-color: blueviolet;
        margin-bottom: 50px;
      }

      .box-rem {
        width: 5rem;
        height: 3rem;
        background-color: aqua;
      }
    </style>
  </head>
  <body>
    <div class="box-px"></div>
    <div class="box-rem"></div>

    <script>
      function ResetHTMLFontSize() {
        document.documentElement.style.fontSize = screen.width / 10 + "px";
      }

      // 绑定事件，不要加括号
      window.onresize = ResetHTMLFontSize;
    </script>
  </body>
</html>
